﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Host.Models;

namespace Host.Controllers
{
    public class ReportsController : Controller
    {
        //
        // GET: /Reports/
        [Authorize(Roles = "Administrator, Developer")]
        public ActionResult Reports()
        {
            return View();
        }

        public ActionResult GetReport(List<Models.FileExceptionLog> data)
        {
            int fundId = 0;
            if (data != null)
            {
                fundId = (int)data[0].FundId;
            }
            int reportTypeId = 0;
            if (data != null)
            {
                 reportTypeId = (int) data[0].SourceId;
            }
            JsonResult result = new JsonResult();
            using (Models.Data db = new Data())
            {
              var q   =
                    db.FileExceptionLog.Where(i => i.FundId == fundId && i.SourceId == reportTypeId).Select(
                        x => x).ToList();
                List<FileExceptionLog> list = new List<FileExceptionLog>();
                foreach (var fileExceptionLog in q)
                {
                    list.Add(new FileExceptionLog
                                 {
                                     ExceptionDescription = fileExceptionLog.ExceptionDescription,
                                     RaisedDateTime = fileExceptionLog.RaisedDateTime.ToShortDateString()
                                 });
                }
                result.Data = list;
            }
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        
    }

    public class FileExceptionLog
    {
        public string ExceptionDescription { get; set; }
        public string RaisedDateTime { get; set; }
    }
}
